<!--$Id: db_close.so,v 10.55 2004/08/13 03:38:55 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB: DB-&gt;close</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<table width="100%"><tr valign=top>
<td>
<b>DB-&gt;close</b>
</td>
<td align=right>
<a href="../api_c/api_core.html"><img src="../images/api.gif" alt="API"></a>
<a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a></td>
</tr></table>
<hr size=1 noshade>
<tt>
<b><pre>
#include &lt;db.h&gt;
<p>
int
DB-&gt;close(DB *db, u_int32_t flags);
</pre></b>
<hr size=1 noshade>
<b>Description: DB-&gt;close</b>
<p>The DB-&gt;close method flushes any cached database information to disk,
closes any open cursors, frees any allocated resources, and closes any
underlying files.</p>
<p>The <a href="../api_c/db_class.html">DB</a> handle should not be closed while any other handle that
refers to it is not yet closed; for example, database handles must not
be closed while cursor handles into the database remain open, or
transactions that include operations on the database have not yet been
committed or aborted.  Specifically, this includes <a href="../api_c/dbc_class.html">DBC</a> and
<a href="../api_c/txn_class.html">DB_TXN</a> handles.</p>
<p>Because key/data pairs are cached in memory, failing to sync the file
with the DB-&gt;close or <a href="../api_c/db_sync.html">DB-&gt;sync</a> method may result in
inconsistent or lost information.</p>
<p>When called on a database that is the primary database for a secondary
index, the primary database should be closed only after all secondary
indices which reference it have been closed.</p>
<p>When multiple threads are using the <a href="../api_c/db_class.html">DB</a> concurrently, only a single
thread may call the DB-&gt;close method.</p>
<p>The <a href="../api_c/db_class.html">DB</a> handle may not be accessed again after DB-&gt;close is
called, regardless of its return.</p>
<p>The DB-&gt;close method
returns a non-zero error value on failure
and 0 on success.
</p>
<b>Parameters</b> <br>
 <b>flags</b><ul compact><li>The <b>flags</b> parameter must be set to 0 or by bitwise inclusively <b>OR</b>'ing together one
or more of the following values:
<br>
<b><a name="DB_NOSYNC">DB_NOSYNC</a></b><ul compact><li>Do not flush cached information to disk.  The <a href="../api_c/db_close.html#DB_NOSYNC">DB_NOSYNC</a> flag is
a dangerous option.  It should be set only if the application is doing
logging (with transactions) so that the database is recoverable after
a system or application crash, or if the database is always generated
from scratch after any system or application crash.
<p><b>It is important to understand that flushing cached information to disk
only minimizes the window of opportunity for corrupted data.</b> Although
unlikely, it is possible for database corruption to happen if a system
or application crash occurs while writing data to the database.  To
ensure that database corruption never occurs, applications must either:
use transactions and logging with automatic recovery; use logging and
application-specific recovery; or edit a copy of the database, and once
all applications using the database have successfully called
DB-&gt;close, atomically replace the original database with the
updated copy.</p></ul>
<br></ul>
<br>
<br><b>Errors</b>
<p>The DB-&gt;close method
may fail and return one of the following non-zero errors:</p>
<br>
<b>EINVAL</b><ul compact><li>An
invalid flag value or parameter was specified.</ul>
<br>
<hr size=1 noshade>
<br><b>Class</b>
<a href="../api_c/db_class.html">DB</a>
<br><b>See Also</b>
<a href="../api_c/db_list.html">Databases and Related Methods</a>
</tt>
<table width="100%"><tr><td><br></td><td align=right>
<a href="../api_c/api_core.html"><img src="../images/api.gif" alt="API"></a><a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a>
</td></tr></table>
<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
</body>
</html>
